from openpyxl.pivot.fields import Boolean
from pygments.lexer import default


from app.exts import db
from datetime import datetime
import pytz
blog_tag=db.Table('blog_tag',
                  db.Column('blog_id',db.Integer,db.ForeignKey('blog.id'),primary_key=True),
                  db.Column('tag_id',db.Integer,db.ForeignKey('tag.id'),primary_key=True)
                  )

class BlogModel(db.Model):
    __tablename__='blog'
    id=db.Column(db.Integer,primary_key=True,autoincrement=True)
    title=db.Column(db.String(100),nullable=False,unique=True)
    content=db.Column(db.Text,nullable=False)
    create_time=db.Column(db.DateTime,default=datetime.now)
    picture=db.Column(db.String(300))
    status=db.Column(db.String(20),default='Published')
    # update_time=db.Column(db.DateTime,default=datetime.utcnow,onupdate=datetime.utcnow)
    update_time = db.Column(
        db.DateTime,
        default=lambda: datetime.now(pytz.timezone('Asia/Shanghai')),
        onupdate=lambda: datetime.now(pytz.timezone('Asia/Shanghai')),
        comment='更新时间（本地时区）'
    )
    is_deleted=db.Column(db.Boolean,default=False)
    tags=db.relationship("TagModel",secondary=blog_tag,backref=('blogs'))

    categorie_id=db.Column(db.Integer,db.ForeignKey('categories.id'))
    categorie=db.relationship("CategoriesModel",back_populates="blogscat")

    author_id=db.Column(db.Integer,db.ForeignKey('user.id'))
    author=db.relationship("UserModel",back_populates="blogs")

    topic_id=db.Column(db.Integer,db.ForeignKey('topic.id'))
    topic=db.relationship("TopicModel",back_populates="blogstop")